import { message } from 'antd';
import * as caseServices from '../services/case';

export default {
  namespace: 'smokereport',
  state: {
    smokereportinfo: [],
    projectlist: [],
  },
  reducers: { // 修改state
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
  effects: {
    *fetchProjectList({ payload }, { call, put }) {
      const { data } = yield call(caseServices.GetProjectList);// 接口调用
      yield put({
        type: 'save',
        payload: {
          projectlist: data.data.objects || [], // 逻辑表达式，前面为空则用后面的值
        },
      });
    },
    *fetchSmokeResult({ payload: { params } }, { call, put }) {
      const { data } = yield call(caseServices.getSmokeResult, params);// 接口调用
      yield put({
        type: 'save',
        payload: {
          smokereportinfo: data.data || [], // 逻辑表达式，前面为空则用后面的值
        },
      });
    },
  },

  subscriptions: {
    setup({ dispatch, history }) {
      return history.listen(({ pathname }) => {
        if (pathname.includes('/casemanage')) {
          dispatch({ type: 'fetchProjectList' });
        }
      });
    },
  },
};
